#ifndef NETWORK_CLIENT_H__
#define NETWORK_CLIENT_H__

#include "network_libevent.h"
#include "network_stream.hpp"
#include <list>

namespace engine
{
	class NetworkClientListener
	{
	public:
		virtual void onConnected() = 0;
		virtual void onConnectFailed() = 0;
		virtual void onDisconnected() = 0;
		virtual void onMessage(NetworkStream& stream) = 0;
	};

	class NetworkClient
	{
	public:
		NetworkClient() : mHost(NULL) {}

		bool connect(const char* host, uint16 port);
		
		void disconnect();

		virtual NetworkStream& beginStream();
		virtual void sendStream(const NetworkStream& stream);

		void addListener(NetworkClientListener* listener);
		void removeListener(NetworkClientListener* listener);

		void handleMessages();

	private:
		LibEvent mLibEvent;
		NetworkStream mSendStream;
		NetworkStream mRecvStream;
		Connection* mHost;

		typedef std::list<NetworkClientListener*> ListenerList;
		ListenerList mListeners;
	};
}


#endif
